namespace WebRtcProject.Models.Configuration
{
    public class SerilogOptions
    {
        public const string SectionName = "Serilog";

        // 基础配置
        public string MinimumLevel { get; set; } = "Information";
        public bool EnableConsoleOutput { get; set; } = true;
        public bool EnableFileOutput { get; set; } = true;
        
        // 异步配置
        public AsyncOptions Async { get; set; } = new();
        
        // 文件输出配置
        public FileOptions File { get; set; } = new();
        
        // 性能关键路径配置
        public PerformanceOptions Performance { get; set; } = new();
        
        // 资源控制配置
        public ResourceControlOptions ResourceControl { get; set; } = new();
    }

    public class AsyncOptions
    {
        public bool Enabled { get; set; } = true;
        public int BufferSize { get; set; } = 10000;
        public int BlockWhenFull { get; set; } = 0; // 0 = 不阻塞，丢弃日志
        public TimeSpan FlushToDiskInterval { get; set; } = TimeSpan.FromSeconds(2);
        public int MaxDegreeOfParallelism { get; set; } = Environment.ProcessorCount;
    }

    public class FileOptions
    {
        public string Path { get; set; } = "logs/webrtc-.txt";
        public string RollingInterval { get; set; } = "Day"; // Day, Hour, Minute
        public string FileSizeLimitBytes { get; set; } = "100MB";
        public int RetainedFileCountLimit { get; set; } = 31;
        public bool Buffered { get; set; } = true;
        public int FlushToDiskInterval { get; set; } = 1; // 秒
        public bool RollOnFileSizeLimit { get; set; } = true;
        public bool Shared { get; set; } = false;
        public string OutputTemplate { get; set; } = 
            "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] [{SourceContext}] [{ThreadId}] {Message:lj}{NewLine}{Exception}";
    }

    public class PerformanceOptions
    {
        // 快速路径日志级别（这些级别的日志会优化处理）
        public string[] FastPathLevels { get; set; } = { "Error", "Fatal" };
        
        // 性能关键的命名空间（这些命名空间的日志会被特殊处理）
        public string[] CriticalNamespaces { get; set; } = 
        {
            "WebRtcProject.Hubs.SignalingHub",
            "WebRtcProject.Services.RabbitMQService"
        };
        
        // 启用结构化日志的命名空间
        public string[] StructuredLoggingNamespaces { get; set; } = 
        {
            "WebRtcProject.Services",
            "WebRtcProject.Hubs"
        };
        
        // 采样配置
        public SamplingOptions Sampling { get; set; } = new();
    }

    public class SamplingOptions
    {
        public bool Enabled { get; set; } = false;
        public int SampleRate { get; set; } = 100; // 每100条日志记录1条
        public string[] ExcludedLevels { get; set; } = { "Error", "Fatal" }; // 这些级别不参与采样
    }

    public class ResourceControlOptions
    {
        // 内存使用控制
        public long MaxMemoryUsageMB { get; set; } = 256;
        
        // 磁盘使用控制
        public long MaxTotalLogSizeMB { get; set; } = 10240; // 10GB
        
        // 清理策略
        public CleanupOptions Cleanup { get; set; } = new();
        
        // 限流配置
        public RateLimitOptions RateLimit { get; set; } = new();
    }

    public class CleanupOptions
    {
        public bool AutoCleanup { get; set; } = true;
        public TimeSpan CleanupInterval { get; set; } = TimeSpan.FromHours(6);
        public int MaxLogAge { get; set; } = 30; // 天
        public bool CompressOldLogs { get; set; } = true;
    }

    public class RateLimitOptions
    {
        public bool Enabled { get; set; } = true;
        public int MaxLogEntriesPerSecond { get; set; } = 1000;
        public int BurstCapacity { get; set; } = 5000;
        public TimeSpan TimeWindow { get; set; } = TimeSpan.FromSeconds(1);
    }
} 